package comptadub

class EnvoiMailJob {

    def mailService

    static triggers = {
        cron name: 'mail', cronExpression: "0 /5 * * * ?"
    }

    def execute() {
        def listMail = EnvoiMail.findAllByEnvoye(false) //mails non envoyés

        /* envoi du mail */
        listMail.each {
            def envoiMail = it
            
            mailService.sendMail {
                to      envoiMail.destinataire
                subject envoiMail.sujet
                body    envoiMail.corps
            }

            envoiMail.envoye = true
            envoiMail.save()
        }
    }
}
